<?php

// $Id$


require_once($WSC->get_site_inc_dir().'modules/tangra_cms/_sys/tcms_admin_web_page_wed_ua.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_type_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_type_attr_dbc.class.php');


class CI_Type_Manage_WP extends TCMS_Admin_Web_Page_WED_UA {
	public function create_view($name = 'default') {
		$ret = new TCMS_Admin_Page_View($this, $name, 'modules/tangra_cms/pages/_ci/');

		return $ret;
	}


	public function init() {
		parent::init();

		$v = $this->create_view();
		$this->add_view($v);

		$v2 = $this->create_view('not_exist');
		$this->add_view($v2);

		$manage_event = new Web_Event_Simple_Int('manage', Tangra_Parameter_Method::GET, 'manage');
		$this->wed->add_wed_event_action_pair($manage_event, 'manage_event', 20);
	}


	protected function manage_event($ci_type_id) {
		$dbc = $this->get_dbc();

		$ci_type = new TCMS_CI_Type_DBC();
		if ($ci_type->load_by_id($dbc, $ci_type_id)) {
			$this->export('ci_type', $ci_type);

			$attributes = TCMS_CI_Type_Attr_DBC::select_all_for_ci_type($dbc, $ci_type_id);

			$this->export('attributes', $attributes);

			$view = $this->get_view('default');
		} else {
			$view = $this->get_view('not_exist');
		}

		return $view;
	}


	protected function default_event() {
		throw new Tangra_Module_Exception('Expecting manage parameter.');
	}
}